import { createSlice, createAsyncThunk } from '@reduxjs/toolkit';
import { getType } from '../api/type';

export const getTypeList = createAsyncThunk('type/getTypeList', async () => {
  const response = await getType();
  return response.data;
});

export const typeSlice = createSlice({
  name: 'type',
  initialState: {
    typeList: [],
  },
  reducers: {
    setTypeList: (state, action) => {
      state.typeList = action.payload;
    },
  },

  extraReducers: (builder) => {
    builder.addCase(getTypeList.fulfilled, (state, action) => {
      state.typeList = action.payload;
    });
  },
});

export const { setTypeList } = typeSlice.actions;
export default typeSlice.reducer;
